#include "RaiderBulletHandler.h"


RaiderBulletHandler::RaiderBulletHandler() {
}


RaiderBulletHandler::~RaiderBulletHandler() {
}


void RaiderBulletHandler::initialize(sf::RenderWindow* window)
{
	m_renderWindow = window;
	m_bulletImg = new sf::Texture();
	m_bulletImg->loadFromFile("bilder/weapons/enemybullet.png");
}

void RaiderBulletHandler::addBullet(float rotation, sf::Vector2f position)
{
	raiderBulletObj = new RaiderBullets();
	raiderBulletObj->initialize(m_renderWindow, rotation, position, m_bulletImg);
	RaiderBulletArray.push_back(raiderBulletObj);
}

void RaiderBulletHandler::update()
{
	for(int i = 0; i < RaiderBulletArray.size(); i++) {
		RaiderBulletArray[i]->update();
		
		if(RaiderBulletArray[i]->m_bulletSprite->getPosition().x < 0 || 
			RaiderBulletArray[i]->m_bulletSprite->getPosition().x > 2560 ||
			RaiderBulletArray[i]->m_bulletSprite->getPosition().y < 0 ||
			RaiderBulletArray[i]->m_bulletSprite->getPosition().y > 1440)
		{
			RaiderBulletArray[i]->cleanup();
			delete RaiderBulletArray[i];
			RaiderBulletArray.erase (RaiderBulletArray.begin()+i);
		}
		
	}
}

void RaiderBulletHandler::cleanup()
{

}
